<?php
/**
 * Created by PhpStorm.
 * User: 123
 * Date: 2020/9/8
 * Time: 16:06
 */

namespace app\service;

use think\Db;

/**
 * 利润服务层
 * @author   juzi
 * @blog    https://blog.csdn.net/juziaixiao
 * @version  0.0.1
 * @datetime 2020年7月22日10:57:35
 */
class ProfitService extends BaseService
{


    /**
     * 利润列表条件
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version  0.0.1
     * @datetime 2020年7月24日13:22:12
     * @param    [array]          $params [输入参数]
     */
    public static function ProfitListWhere($params = [])
    {

        $where = [];

        //利润时间
        if(!empty($params['create_time']))
        {

            $where[] = ['create_time', '>', explode(' - ',$params['create_time'])[0]];
            $where[] = ['create_time', '<', explode(' - ',$params['create_time'])[1]];
        }

        $where[] = ['id', '>', 0];


        return $where;
    }

    /**
     * 数据处理
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version 1.0.0
     * @date    2020年7月21日13:29:33
     * @desc    description
     * @param   [array]          $data [广告数据 二维数组]
     */
    public static function DealWith($data)
    {
       // dump($data);exit;
        if(!empty($data) && is_array($data))
        {
            foreach($data as &$v)
            {
                $v['income_price']=number_format($v['income_price'],2);
                $v['pay_price']=number_format($v['pay_price'],2);
                $v['total_price']=number_format($v['total_price'],2);
            }
        }

        return $data;
    }

    /**
     * 利润统计
     * @author   juzi
     * @blog    https://blog.csdn.net/juziaixiao
     * @version 1.0.0
     * @date    2020年7月21日13:29:33
     * @desc    description
     * @param    [array]          $where [条件
     */
    public static function ProfitDataTotal($where){
        $data=[];
        $data['income_price']= (float) Db::name('log_profits')->where($where)->sum('income_price');
        $data['pay_price']=(float) Db::name('log_profits')->where($where)->sum('pay_price');
        $data['total_price']=(float) Db::name('log_profits')->where($where)->sum('total_price');
        return $data;
    }
}